package se.statemachine.fsm.mvcstyle;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import se.statemachine.fsm.interfacestyle.TurnstileFSM;

public class Controller implements ActionListener{
	
	private View view;
	private Model model;
	
	private TurnstileFSM fsm;
	
	public void initComponent(){
		model.initComponent();		
		view.initComponent(model.getPassAction(), model.getCoinAction(), fsm.getCurrentState());		
	}
	
	public void actionPerformed(ActionEvent e) {	

		if(e.getActionCommand().equals(model.getCoinAction())){
			fsm.coin();	
		}
		if(e.getActionCommand().equals(model.getPassAction())){
			fsm.pass();			
		}	
		
		view.setCurrentState( fsm.getCurrentState());
		view.update();
	}

	public void setView(View view) {
		this.view = view;
	}

	public void setModel(Model model) {
		this.model = model;
	}

	public void setTurnstileFsm(TurnstileFSM fsm) {
		this.fsm = fsm;
	}				
}
